//
//  FZAdvertisementService.m
//  KidDubbing
//
//  Created by Victor Ji on 16/8/28.
//  Copyright © 2016年 Feizhu Tech. All rights reserved.
//

#import "FZAdvertisementService.h"
#import "FZAdsParamData.h"
#import <SRNetworkBaseAF.h>
#import "FZAdvertisementModel.h"

NSString * const kThirdPartyAds = @"third_advert";
NSString * const kFZVideoAds = @"video";

@implementation FZAdvertisementService

+ (void)getAdsWithType:(FZAdsType)type success:(FZSuccessBlock)success failure:(FZFailureBlock)failure {
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setValue:[self getTypeStringWithType:type] forKey:@"type"];
    
    NSString *urlString = [[SRAPICreater sharedInstance] APIWithName:@"basic_advert"];
    [[SRNetWorkManager sharedInstance] GET:urlString needCache:NO parameters:params timeout:2.0f responseClass:[FZAdvertisementModel class] success:^(NSInteger statusCode, NSString *message, id dataObject) {
        if (success) {
                //过滤vip显示问题：show_type = 0 通用都显示，1 仅VIP显示，2 仅非VIP显示
            NSArray *adLists = dataObject;
            if (adLists && [adLists isKindOfClass:[NSArray class]]) {
                success(statusCode, message, dataObject);
            }
            else {
                success(statusCode, message, dataObject);
            }
        }
    } failure:failure];
}

+ (NSString *)getTypeStringWithType:(FZAdsType)type {
    NSString *typeString = @"";
    switch (type) {
        case FZAdsTypeBanner:
            typeString = @"banner";
            break;
        case FZAdsTypeiShow:
            typeString = @"ishow";
            break;
        case FZAdsTypeCourseVideo:
            typeString = @"course_video";
            break;
        case FZAdsTypeCourse:
            typeString = @"course";
            break;
        case FZAdsTypeShare:
            typeString = @"share";
            break;
        case FZAdsTypeLaunch:
            typeString = @"home";
            break;
        case FZAdsTypeRankList:
            typeString = @"top";
            break;
        case FZAdsTypeFinishShare:
            typeString = @"show_end";
            break;
        case FZAdsTypeMessage:
            typeString = @"message";
            break;
        case FZAdsTypeAppRecommendTools:
            typeString = @"tools";
            break;
        case FZAdsTypeHot:
            typeString = @"hot_show";
            break;
        case FZAdsTypeConcern:
            typeString = @"follow_list";
            break;
        default:
            break;
    }
    return typeString;
}

+ (FZThirdPartyAdsType)getThirdPartyType:(NSString *)typeString {
    NSString *lowerStr = [typeString lowercaseString];
    if ([lowerStr isEqualToString:@"baidu"]) {
        return FZThirdPartyAdsTypeBaidu;
    } else if ([lowerStr isEqualToString:@"tencent"]) {
        return FZThirdPartyAdsTypeTencent;
    } else if ([lowerStr isEqualToString:@"inmobi"]) {
        return FZThirdPartyAdsTypeInmobi;
    } else if ([lowerStr isEqualToString:@"harmight"]) {
        return FZThirdPartyAdsTypeHarmight;
    } else if ([lowerStr isEqualToString:@"iflytek"]) {
        return FZThirdPartyAdsTypeIfly;
    } else {
        return FZThirdPartyAdsTypeNone;
    }
}

@end
